package com.code;

/**
 * 移除相同的数
 * Created by lucky on 2018/9/27.
 */
public class Code5 {

    public static void main(String[] args) {
        int[] nums = new int[]{1,2,2,1,3,4,2};
        int len = removeDuplicates(nums);

        for (int i = 0; i < len; i++) {
            System.out.println(nums[i]);
        }

    }

    public static int removeDuplicates(int[] nums) {
        int length = nums.length;
        for(int i = 0 ; i < length ; i++){
            int a = nums[i];
            if(i+1 >= length){
                return length;
            }
            int b = nums[i+1];
            while(a==b){
                for(int j = i + 1 ; j < length - 1; j++){
                    nums[j] = nums[j+1];
                }
                b = nums[i+1];
                if(i+1 >= length){
                    return length;
                }
                length --;
                if(length == 1){
                    break;
                }
            }
        }
        return length;
    }
}
